#include <iostream>

#include "IfThenElse.hpp"

#include "Expression.hpp"
#include "ExpressionValue.hpp"

IfThenElse::IfThenElse(Expression* _condition, Instruction* _codeExec, Instruction* _codeExecElse)
{
    condition = _condition;
    codeExec = _codeExec;
    codeExecElse = _codeExecElse;
}

void IfThenElse::execute()
{
    condition->compute();
    if (getBoolean(condition->getValue()))
    {
        codeExec->execute();
    }
    else
    {
        codeExecElse->execute();
    }
}

void IfThenElse::display(const unsigned int shift) const
{
    std::cout << "if (";
    condition->display();
    std::cout << ")\n";
    std::cout << "{\n";
        std::cout << "\t";
        codeExec->display();
        std::cout << "\n";
    std::cout << "}\n";
    std::cout << "else\n";
    std::cout << "{\n";
        std::cout << "\t";
        codeExecElse->display();
        std::cout << "\n";
    std::cout << "}\n";
}

IfThenElse::~IfThenElse() {}